package lxy;

public class SleepTest {
    public static void t1(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                String str = "Hello World";
                for (int i = 0; i < str.length(); i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(str.charAt(i));
                }
            }
        }).start();
    }

    public static void t2(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "---" + i);
                }
            }
        }).start();
    }
    public static void main(String[] args) {
        t2();
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "---" + i);
        }
    }
}
